package cn.lg.soar.system.auth.model;

import cn.lg.soar.common.util.BeanCopier;
import cn.lg.soar.common.util.trans.annotations.Translate;
import cn.lg.soar.database.translate.TranslateByEntity;
import cn.lg.soar.system.tenant.entity.Tenant;
import cn.lg.soar.system.auth.entity.User;
import cn.lg.soar.system.handler.UserStatusTranslateHandler;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Getter
@Setter
public class UserVo implements Serializable {

    private static final long serialVersionUID = 6850908496978491051L;

    public final static BeanCopier<User, UserVo> FROM_ENTITY = BeanCopier.create(User.class, UserVo.class);
    public final static BeanCopier<UserVo, User> TO_ENTITY = BeanCopier.create(UserVo.class, User.class);

    @ApiModelProperty(value = "主键id")
    private Long id;

    @ApiModelProperty(value = "用户名（账号）", example = "test-user")
    private String username;

    @ApiModelProperty(value = "昵称", example = "测试用户")
    private String nickname;

    @ApiModelProperty(value = "头像")
    private String avatar;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @ApiModelProperty(value = "最后登录时间")
    private LocalDateTime lastLoginDate;

    @ApiModelProperty(value = "当前所属租户id")
    @TranslateByEntity(Tenant.class)
    private Integer currentTenantId;

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @ApiModelProperty(value = "用户类型（根据系统需要配置）")
    private Integer userType;

    @Translate(UserStatusTranslateHandler.class)
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @ApiModelProperty(value = "状态（根据系统需要配置）")
    private Integer status;

    public UserVo() {
    }

    public UserVo(User data) {
        FROM_ENTITY.copy(data, this);
    }

    public User toUser(){
        return TO_ENTITY.convert(this);
    }
}
